package com.tinem.platform.web.auth.config;

import cn.hutool.core.codec.Base64;
import cn.hutool.crypto.SecureUtil;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.time.Duration;

/**
 * @author fengzhihao
 * @version v1
 * @program: platform
 * @className JwtConfig
 * @description TODO
 * @site 
 * @company 
 * @create 2020-06-18 19:58
 */
@Data
@Configuration
@ConfigurationProperties(prefix = "jwt")
public class JwtConfig {
    private String iss;
    private String verifierKey;
    private RSAPrivateKey pv;
    private RSAPublicKey pu;

    private Duration accessTokenValiditySeconds;
    private Duration refreshTokenValiditySeconds;

    public void setPv(String pv){
        this.pv = (RSAPrivateKey) SecureUtil.generatePrivateKey("RSA", Base64.decode(pv));
    }

    public void setPu(String pu){
        verifierKey = pu;
        this.pu = (RSAPublicKey) SecureUtil.generatePublicKey("RSA", Base64.decode(pu));
    }
}
